<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container>
      <a-form-model layout="horizontal" ref="subForm" slot="detail" :model="model" :rules="validatorRules"
        v-bind="formItemLayout">
        <z-form-item :datas="fieldArr" :form="model" :rules="validatorRules" :gutter="0">
        </z-form-item>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { continueApply } from '@/api/sjsk/personService'
import { getAbortDatail } from '@/api/sjsk/flowService'
export default {
  data() {
    return {
      model: {},
      confirmLoading: false,
      formItemLayout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 16 }
      },
      fieldArr: [
        { label: '姓名', prop: 'name', tagType: 'input', disabled: true },
        { label: '类型', prop: 'sjskType', tagType: 'dict-select', dictCode: 'risk_level_person_type', disabled: true },
        { label: '性别', prop: 'sex', tagType: 'dict-select', dictCode: 'sex', disabled: true },
        { label: '身份证号', prop: 'identityCard', tagType: 'input', disabled: true },
        { label: '中止开始时间', prop: 'abortStartDate', tagType: 'date-picker', format: 'YYYY-MM-DD', showTime: false, disabled: true },
        { label: '中止原由', prop: 'abortReason', tagType: 'dict-select', dictCode: 'abort_reason', disabled: true },
        { label: '继续执行时间', prop: 'continueTime', tagType: 'date-picker', format: 'YYYY-MM-DD', showTime: false },
        { label: '法定原由', prop: 'legalReason', tagType: 'dict-select', dictCode: 'legal_Reason' },
        { label: '法院判处刑罚', prop: 'punishment', tagType: 'textarea', },
        { label: '证明材料', prop: 'file', tagType: 'upload-file', fileDescribe: '可上传多个文件', fileFormat: '.doc,.docx,.xls,.xlsx,.pdf,.jpg,.jpeg,.png' },
      ],
      validatorRules: {
        continueTime: [{ required: true, message: '请选择继续执行时间' }],
        legalReason: [{ required: true, message: '请选择法定原由' },],
      }
    }
  },
  methods: {
    show(record) {
      // this.model = record?Object.assign({}, record):this.model;
      // this.$set(this.model, 'sjskPersonId', record.id)
      // this.$set(this.model, 'name', record.realName)
      // this.$set(this.model, 'sex', record.sex)
      // this.$set(this.model, 'sjskType', record.sjskType)
      // this.$set(this.model, 'identityCard', record.identityCard)
      // this.$set(this.model, 'abortReason', record.abortReason)
      this.getDetail(record.id)
    },
    getDetail(id) {
      getAbortDatail(id)
        .then(res => {
          if (res.result) {
            this.$set(this.model, 'abortId', res.result.id)
            this.$set(this.model, 'sjskPersonId', res.result.sjskPersonId)
            this.$set(this.model, 'name', res.result.name)
            this.$set(this.model, 'sex', res.result.sex)
            this.$set(this.model, 'sjskType', res.result.sjskType)
            this.$set(this.model, 'identityCard', res.result.identityCard)
            this.$set(this.model, 'abortStartDate', res.result.abortStartDate)
            this.$set(this.model, 'abortReason', res.result.abortReason)
          }
        })
    },
    submitForm() {
      const parameter = Object.assign({}, this.model)
      this.$refs.subForm.validate((valid) => {
        if (valid) {
          continueApply(parameter)
            .then(res => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success(res.message)
                this.$emit('ok');
              } else {
                this.$message.warn(res.message)
              }
            })
            .catch(e => {
              this.$message.warn('请求失败！')
              this.confirmLoading = false
            })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  }
}
</script>
